﻿@using DevExpress.Blazor
@using DevExpress.ExpressApp.Blazor;
@using DevExpress.ExpressApp.Blazor.Components
@using DevExpress.ExpressApp.Blazor.Templates
@using Microsoft.AspNetCore.Components.Web

@inherits FrameTemplateComponentBase<MdiMainWindowTemplate>

<div id="main-window-template-component" class="app h-100 d-flex flex-column">
    <ComponentModelObserver ComponentModel="@FrameTemplate.NavigateBackActionControl.ButtonModel">
        <div class="header d-flex flex-row shadow-sm navbar-dark flex-nowrap @DetailViewHeaderClass @NavigateBackActionHeaderClass">
            <div class="header-left-side d-flex align-items-center ps-2">
                <button class="btn-hamburger p-0 btn btn-secondary btn-header">
                    <XafImage ImageName="Hamburger" Size="24" Styles="margin: auto;" />
                </button>
                <div class="header-logo mx-3"></div>
            </div>
            <div class="header-right-side w-100 overflow-hidden d-flex align-items-center ps-4">
                @if (!FrameTemplate.CanShowTabbedMdi)
                {
                    @FrameTemplate.NavigateBackActionControl.GetComponentContent()
                }
                <ViewCaptionComponent WindowCaption="@FrameTemplate" />
                <SizeModeContainer>
                    @FrameTemplate.HeaderToolbar.GetComponentContent()
                </SizeModeContainer>
                <div class="d-flex ms-auto">
                    @FrameTemplate.AccountComponent.GetComponentContent()
                    <SettingsComponent />
                </div>
                @if (FrameTemplate.CanWindowKeepOpen)
                {
                    <div class="d-flex align-items-center pe-2">
                        <button class="p-0 btn btn-secondary btn-header" onclick="@(()=>FrameTemplate.ShowWindowListDialog())">
                            <XafImage Styles="margin:auto;" Size="24" ImageName="Action_WindowList" />
                        </button>
                    </div>
                }
            </div>
        </div>
    </ComponentModelObserver>
    <div class="xaf-flex-auto overflow-hidden d-flex">
        <div class="xaf-sidebar sidebar d-none d-sm-flex flex-column">
            @FrameTemplate.ShowNavigationItemActionControl.GetComponentContent()
            <div class="about-info mx-3 mb-4">
                @((MarkupString)FrameTemplate.AboutInfoString)
            </div>
        </div>
        <div class="sidebar-sm-shadow"></div>
        <div class="main xaf-flex-auto overflow-hidden d-flex flex-column">
            <SizeModeContainer>
                @if (IsFirstRenderCompleted)
                {
                    var currentWindowGroup = FrameTemplate.CurrentWindowGroup;
                    var currentWindow = currentWindowGroup.CurrentWindow;

                    @if (FrameTemplate.CanShowTabbedMdi)
                    {
                        <MdiTabComponent WindowTemplate="FrameTemplate" />

                        @foreach (var window in currentWindowGroup.Windows)
                        {
                            <div @key="window" class="xaf-flex-auto d-flex flex-column @(window == currentWindow ? "" : "d-none")">
                                <MdiTabPageComponent Window="window" />
                            </div>
                        }
                    }
                    else
                    {
                        @(((IComponentContentHolder)currentWindow.Template)?.GetComponentContent())
                    }
                }
            </SizeModeContainer>
        </div>
    </div>
</div>

@code {
    public static RenderFragment Create(MdiMainWindowTemplate applicationWindowTemplate)
    {
        return @<MdiMainWindowTemplateComponent FrameTemplate="@applicationWindowTemplate" />;
    }
}
